<template>
  <div>dataconver</div>
</template>

<script>
import { res, dataFormSupplierInput, diffAttrList } from "./data.js";
export default {
  data() {
    return {
      res,
      // 拿supplierInfoFormDB的数据 供应商库的供应商信息
      supplierInfoFormDB: {},
      //dataFormSupplierInput  供应商详情信息
      dataFormSupplierInput,
      // diffAttrList,
      diffData: [],
    };
  },
  methods: {
    getSupplierInfoFormDB() {
      const supplierInfoFormDB = this.composeDataFormDB(this.res);
      Object.assign(this.supplierInfoFormDB, supplierInfoFormDB);
    },
    composeDataFormDB(rawData) {
      const cData = {};
      diffAttrList.forEach((item) => {
        cData[item.attrNameOfSupplier] = rawData[item.attrNameOfDB];
        console.log();
      });
      return cData;
    },
    calculateDiffData() {
      const dataFormSupplierInput = this.dataFormSupplierInput;
      const { supplierInfoFormDB } = this;
      const diffData = [];
      for (const { label, attrNameOfDB, attrNameOfSupplier } of diffAttrList) {
        if (
          supplierInfoFormDB[attrNameOfDB] === undefined ||
          supplierInfoFormDB[attrNameOfSupplier] === null
        ) {
          continue;
        }
        if (
          dataFormSupplierInput[attrNameOfDB] === undefined ||
          dataFormSupplierInput[attrNameOfSupplier] === null
        ) {
          continue;
        }
        // console.log(attrNameOfDB,36);

        if (Array.isArray(attrNameOfDB && attrNameOfSupplier)) {
          diffData.push({
            diffPropertyName: label,
            propertyValueFormDB: supplierInfoFormDB[attrNameOfDB],
            propertyValueFormSupplier:
              dataFormSupplierInput[attrNameOfSupplier],
          });
          //   console.log(diffData, 60);
        }
        if (
          supplierInfoFormDB[attrNameOfDB] !==
          dataFormSupplierInput[attrNameOfSupplier]
        ) {
          diffData.push({
            diffPropertyName: label,
            propertyValueFormDB: supplierInfoFormDB[attrNameOfDB],
            propertyValueFormSupplier:
              dataFormSupplierInput[attrNameOfSupplier],
          });
          this.diffData = diffData;
        }
        // console.log(this.diffData, 57);
      }
    },
  },
  async mounted() {
    await this.getSupplierInfoFormDB();
    await this.calculateDiffData();
  },
};
</script>
<style scoped></style>
